class Solution {
public:
    int count = 0;
    int ret = 0;
    int order(TreeNode* node)
    {
        if(node == nullptr)
        {
            return 0;
        }
        order(node->left);
        count--;
        if(count == 0)
        {
            ret = node->val;
        }
        order(node->right);
        return 0;
    }
    int kthSmallest(TreeNode* root, int k) {
        count = k;
        order(root);
        return ret;
    }
};